-
Notifications
You must be signed in to change notification settings - Fork 7.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to have remoteTextTracks automatically 'garbage-collected' when sources change #3736
Conversation
if (!sh) { | ||
// Fall back to a native source hander when unsupported sources are | ||
// deliberately set | ||
if (_Tech.nativeSourceHandler) { | ||
sh = _Tech.nativeSourceHandler; | ||
} else { | ||
log.error('No source hander found for the current source.'); | ||
return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The addition of this return
and moving of lines 843-844 to above this conditional block are to fix a tiny issue that may have never been manifest in the wild but which I discovered during a test run.
If a Tech has no nativeSourceHandler
property and selectSourceHandler
returned null
because no matching source handlers were found, then the line later on: this.sourceHandler_ = sh.handleSource(source, this, this.options_);
would throw an exception because sh
would stay null
.
Seems reasonable to me. I agree that it feels like the expected behavior when changing sources would be to clear out remote text tracks. And backward-compatibility is a plus as that would've been my big concern here. I wonder if we ought to do something similar with non-remote tracks? Disable them... or something. Not for this PR, but a general thought. |
7b59df9
to
838e64a
Compare
const htmlTrackElement = new HTMLTrackElement(track); | ||
|
||
if (manualCleanup !== true && manualCleanup !== false) { | ||
// deprecation warning | ||
log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am open to some nice word-smithing here. I feel like coming up with error/warnings is not my strong suit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any reason why we need to deprecate this and not just make the change? This almost seems like a bug. If we decide not to deprecate and to just make the change we can probably make this change much smaller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is because currently, you have to manually cleanup, we're wanting to change it so that by default tracks are cleaned up automatically.
* @return {HTMLTrackElement} | ||
* @method addRemoteTextTrack | ||
*/ | ||
addRemoteTextTrack(options) { | ||
addRemoteTextTrack(options, manualCleanup) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this , manualCleanup = true)
here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having a default option here would make it difficult to do the deprecation warning.
@@ -531,20 +548,33 @@ class Tech extends Component { | |||
* | |||
* @param {Object} options The object should contain values for | |||
* kind, language, label and src (location of the WebVTT file) | |||
* @param {Boolean} manualCleanup if set to false, the TextTrack will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be * @param {boolean} [manualCleanup=true]
, since its optional and defaults to true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also you should add an @depricated
tag to the bottom stating that "The manualCleanup
parameter will be removed in favor of always doing automatic cleanup in the future."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
const htmlTrackElement = new HTMLTrackElement(track); | ||
|
||
if (manualCleanup !== true && manualCleanup !== false) { | ||
// deprecation warning | ||
log.warn('Calling addRemoteTextTrack without explicitly setting the "manualCleanup" parameter to `true` is deprecated and default to `false` in future version of video.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there any reason why we need to deprecate this and not just make the change? This almost seems like a bug. If we decide not to deprecate and to just make the change we can probably make this change much smaller.
838e64a
to
b59701b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Html5 tech needs to update addRemoteTextTrack
as well because it overrides the method and calls super, so, the manualCleanup
option gets lost.
* @return {HTMLTrackElement} | ||
*/ | ||
addRemoteTextTrack(options = {}) { | ||
createRemoteTextTrack(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should probably be private.
return; | ||
} | ||
|
||
addWebVttScript() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
@@ -543,6 +560,14 @@ class Tech extends Component { | |||
return createTrackHelper(this, kind, label, language); | |||
} | |||
|
|||
createRemoteTextTrack(options) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private
4de4731
to
2c584df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…ge-collected' when the source changes
…th emulated and native TextTracks. * Remove the redundancy in Html5 & Tech around remote text tracks. * Changed Tech construction to call emulateTextTracks immediately but defer the creation of the webvtt to the `ready` event, if necessary. * Player now passes along all arguments to the underlying Tech on addRemoteTextTrack.
2c584df
to
b65b872
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still need to test it but code-wise, LGTM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending doc commet/arg changes LGTM
@@ -2525,9 +2525,9 @@ class Player extends Component { | |||
* | |||
* @param {Object} options Options for remote text track |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be {TextTrackList[]} theArgs track to add as remote text tracks
, also theArgs is a weird name, shouldn't it be tracks?
* Creates a remote text track object and returns a html track element | ||
* | ||
* @param {Object} options The object should contain values for | ||
* kind, language, label and src (location of the WebVTT file) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
theRest needs to be added to the doc comment, and the name is a bit weird (maybe it will make more sense to me with a doc comment.)
3e24eb5
to
ad7008a
Compare
* @deprecated The default value of the "manualCleanup" parameter will default | ||
* to "false" in upcoming versions of Video.js | ||
*/ | ||
addRemoteTextTrack(...theArgs) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this needs to be changed from ...theArgs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Right now "remoteTextTracks" persist between source changes and must be removed manually by the user. This is problematic in many cases. It means plugins that change sources, such as the playlist API or videojs-contrib-ads, have to be extremely careful about changes the source and take care to cleanup remoteTextTracks.
We do this because the Video.js API aligns very closely with the media element's native API. I propose that we could be doing more to iron-out the rough patches in the native API. In my opinion, the fact that previous changes to the media-element (adding text track elements) may change the behavior of a source is one of those rough patches.
Specific Changes proposed
Tech#addRemoteTextTrack
now accepts a second parameter - a boolean namedmanualCleanup
which defaults to true preserving backwards compatibility. When that value is set tofalse
the text track will be removed from the video element whenever a source change occurs.A new instance property named
autoRemoteTextTracks_
is added toTech
that keeps track of which TextTracks have automatic life-cycle management.Requirements Checklist